package com.gzu.ltms.entity.table;

import com.mybatisflex.core.query.QueryColumn;
import com.mybatisflex.core.table.TableDef;

import java.io.Serial;

/**
 * 动态运费计算规则 表定义层。
 *
 * @author mm
 * @since 2025-05-06
 */
public class FreightRuleTableDef extends TableDef {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 动态运费计算规则
     */
    public static final FreightRuleTableDef FREIGHT_RULE = new FreightRuleTableDef();

    /**
     * 规则id
     */
    public final QueryColumn RULE_ID = new QueryColumn(this, "rule_id");

    /**
     * 最大重量
     */
    public final QueryColumn MAX_WEIGHT = new QueryColumn(this, "max_weight");

    /**
     * 最小重量
     */
    public final QueryColumn MIN_WEIGHT = new QueryColumn(this, "min_weight");

    /**
     * 每公斤价格
     */
    public final QueryColumn UNIT_PRICE = new QueryColumn(this, "unit_price");

    /**
     * 距离系数
     */
    public final QueryColumn DISTANCE_FACTOR = new QueryColumn(this, "distance_factor");

    /**
     * 所有字段。
     */
    public final QueryColumn ALL_COLUMNS = new QueryColumn(this, "*");

    /**
     * 默认字段，不包含逻辑删除或者 large 等字段。
     */
    public final QueryColumn[] DEFAULT_COLUMNS = new QueryColumn[]{RULE_ID, MIN_WEIGHT, MAX_WEIGHT, UNIT_PRICE, DISTANCE_FACTOR};

    public FreightRuleTableDef() {
        super("", "freight_rule");
    }

    private FreightRuleTableDef(String schema, String name, String alisa) {
        super(schema, name, alisa);
    }

    public FreightRuleTableDef as(String alias) {
        String key = getNameWithSchema() + "." + alias;
        return getCache(key, k -> new FreightRuleTableDef("", "freight_rule", alias));
    }

}
